import { ShallowRef, provide, shallowRef } from 'vue'
import { inject } from 'vue'

const pinBuilderKey = Symbol('pinBuilder')

function useContextPinBuilder() {
    const pinBuilder = inject<ShallowRef<Cesium.PinBuilder>>(pinBuilderKey)
    return pinBuilder
}

function providePinBuilder() {
    const pinBuilderRef = shallowRef(new Cesium.PinBuilder())
    provide(pinBuilderKey, pinBuilderRef)
}

const viewerKey = Symbol('viewerKey')

function useContextViewer() {
    const viewerRef = inject<ShallowRef<Cesium.Viewer>>(viewerKey)

    return viewerRef
}

function provideContextViewer(
    viewerRef: ShallowRef<Cesium.Viewer | undefined>,
) {
    provide(viewerKey, viewerRef)
}

export {
    pinBuilderKey,
    useContextPinBuilder,
    providePinBuilder,
    viewerKey,
    useContextViewer,
    provideContextViewer,
}
